﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Main.Master" Inherits="System.Web.Mvc.ViewPage<IList<DBBackupFileInfo>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <div style="width:1000px;">
        <div style="padding:5px;">
            <%using (Html.BeginForm(MVC.DBBackup.Backup(), FormMethod.Post))
              { %>
            备份日期：<%=Html.TextBox("theDate", null, new { @class = "date-pick", @readonly = true })%>&nbsp;
            <input type="submit" value="创建备份" />
            <%} %>
        </div>
        <div style="width:720px;">
            <table class="table">
                <thead>
                    <tr>
                        <th style="width:250px;">备份文件集</th>
                        <th style="width:80px;">文件大小</th>
                        <th style="width:150px;">创建时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <%if (Model == null)
                  { %>
                <tr>
                    <td colspan="3">暂无任何数据</td>
                </tr>
                <%}
                  else
                  {
                      foreach (var item in Model)
                      {%>
                <tr>
                    <td><%=item.FileName %></td>
                    <td><%=item.ContentLength %>KB</td>
                    <td><%=item.CreationTime %></td>
                    <td>
                    <a href="javascript:void(0);" restoreFor="<%=item.FileName %>" class="restoreThis">恢复</a>
                    <%=Html.ActionLink("下载", MVC.DBBackup.Download(item.FileName))%>
                    <a href="javascript:void(0);" deleteFor="<%=item.FileName %>" class="deleteThis">删除</a>
                    </td>
                </tr>
                <%}
                  } %>
            </table>
        </div>
    </div>
    <script type="text/javascript">
        $(function() {
            $("form", document).ajaxForm({
                dataType: "json",
                beforeSubmit: function() { if ($("#theDate").val() == '') alert("请选择日期"); },
                success: function(data) {
                    alert(data.message);
                    if (data.state == 100) {
                        window.location = window.location;
                    }
                }
            });

            $('.date-pick').datepick();

            $(".restoreThis").click(function() {
                if (confirm("确定要恢复备份吗")) {
                    var url = "<%=Url.Action(MVC.DBBackup.Restore()) %>";
                    $.post(
                    url,
                    { "dbBackupFile": $(this).attr("restoreFor") },
                    function(data) {
                        if (data.state == 100) {
                            alert(data.message);
                        }
                        else {
                            alert(data.message);
                        }
                    },
                    "json");
                    }
            });

            $(".deleteThis").click(function() {
                if (confirm("确定要删除备份吗")) {
                    var url = "<%=Url.Action(MVC.DBBackup.Delete()) %>";
                    $.post(
                url,
                { "dbBackupFile": $(this).attr("deleteFor") },
                function(data) {
                    if (data.state == 100) {
                        window.location = window.location;
                    }
                    else {
                        alert(data.message);
                    }
                },
                "json");
                }
            });
        });
    </script>
</asp:Content>
